package com.demo.servlet.demo1213.servlet;

import com.demo.servlet.demo1213.entity.Person;
import com.demo.servlet.demo1213.service.PersonService;
import com.demo.servlet.demo1213.service.impl.PersonServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/demo1213/demo02.do")
public class Demo02Servlet extends HttpServlet {
    PersonService personService = new PersonServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Person> people = personService.queryAll();
        //把信息放到域对象中
        request.setAttribute("people", people);
        //请求转发 把带有域信息的对象 发送给前端JSP
        request.getRequestDispatcher("/demo1213/2.jsp").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
